package com.mashibing.service.impl;

import com.mashibing.internalcommon.dto.Car;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.ApiDriverPointRequest;
import com.mashibing.internalcommon.request.PointRequest;
import com.mashibing.internalcommon.response.DriverUserExistsResponse;
import com.mashibing.remote.DriverUserClient;
import com.mashibing.remote.ServiceMapClient;
import com.mashibing.service.UploadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UploadServiceImpl implements UploadService {

    @Autowired
    private DriverUserClient driverUserClient;

    @Autowired
    private ServiceMapClient serviceMapClient;

    @Override
    public ResponseResult upload(ApiDriverPointRequest apiDriverPointRequest) {

        // 获取carId
        String carId = apiDriverPointRequest.getCarId();

        // 根据carId查询 tid，trid
        ResponseResult<Car> carResponseResult = driverUserClient.getDriverById(carId);
        Car resultCar = carResponseResult.getData();
        log.info("carId:{}对应car信息:{}",carId,resultCar);

        // 调用map服务上传轨迹
        PointRequest pointRequest = new PointRequest();
        pointRequest.setTrid(resultCar.getTrid());
        pointRequest.setTid(resultCar.getTid());
        pointRequest.setPoints(apiDriverPointRequest.getPoints());
        log.info("最终上传轨迹信息：{}",pointRequest);

        return serviceMapClient.uploadTrack(pointRequest);
    }

    @Override
    public ResponseResult testBug(String carId) {
        log.info("carId:" + carId);
        ResponseResult<Car> carResponseResult = driverUserClient.getDriverById(carId);

        return ResponseResult.success(carResponseResult);
    }


}
